<template>
	<view class="tip_records">
		<view class="tip_records__item" v-for="item in list" :key="item.id">
			<view class="tip_records__time">{{ item.created_at }}</view>
			<view class="tip_records__box">
				<view class="tip_records__left">
					<image class="tip_records__avatar" :src="item.user_info.avatar" mode="aspectFill"></image>
					<view>
						<view class="tip_records__name">送出{{ item.gift.name }}</view>
						<view class="tip_records__video">价值：{{ Number(item.price) }}个钻石</view>
					</view>
				</view>
				<image class="tip_records__cover" :src="item.gift.url" mode="aspectFit"></image>
			</view>
		</view>
		<view class="tip_records__loading">
			<u-loadmore :status="status" />
		</view>
	</view>
</template>

<script>
	import {getTipRecords} from '@/common/api.js'
	
	export default {
		data() {
			return {
				list: [],
				page: 1,
				finished: false,
				status: 'loadmore'
			};
		},
		onShow() {
			this._getTipRecords()
		},
		onReachBottom() {
			if (this.finished) return
			this.page++
			this._getTipRecords()
		},
		methods: {
			_getTipRecords() {
				this.status = 'loading'
				getTipRecords({page: this.page}).then(({data}) => {
					this.status = false
					if (data.current_page === 1) {
						this.list = data.list
					} else {
						this.list = this.list.concat(data.list)
					}
					this.finished = data.current_page >= data.total_page
					this.status = this.finished ? 'nomore' : 'loading'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tip_records__loading {
		padding-top: 40rpx;
		text-align: center;
	}
	.tip_records__name {
		margin-bottom: 10rpx;
		color: #0862EC;
	}
	.tip_records__left {
		display: flex;
		align-items: center;
	}
	.tip_records__avatar {
		width: 150rpx;
		height: 150rpx;
		border-radius: 50%;
		margin-right: 20rpx;
		background-color: #F3F3F3;
	}
	.tip_records__box {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-top: 20rpx;
	}
	.tip_records__item {
		background-color: #fff;
		padding: 20rpx;
		margin: 20rpx 20rpx 0;
		border-radius: 12rpx;
	}
	.tip_records__cover {
		width: 150rpx;
		height: 150rpx;
	}
	.tip_records__time {
		font-size: 24rpx;
		color: #999;
	}
</style>
